<?php
// $Id$

include_once('BaseModel.class.php');

class InboxManagerModel extends BaseModel
{
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='',$u_id='',$u_prv='')
	{
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

		if (is_null($offset)) {
            
	        $query = "SELECT COUNT(*) FROM inbox ibx LEFT JOIN members mem ON mem.msisdn = ibx.msisdn $where AND ibx.folder_id=0 AND ibx.active =1";
		} else {
	        $query = "SELECT CONCAT(mem.firstname,' ',mem.middlename,' ',mem.lastname) as fullname,ibx.* FROM inbox ibx LEFT JOIN members mem ON mem.msisdn = ibx.msisdn $where AND ibx.folder_id=0 AND ibx.active = 1 ORDER BY $by $sort LIMIT $offset,$limit";
		}
		return $this->query($query, true);
    }

    function datalist($search){
		$where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "";
        $query = "SELECT CONCAT(mem.firstname,' ',mem.middlename,' ',mem.lastname) as fullname,ibx.* FROM inbox ibx LEFT JOIN members mem ON mem.msisdn = ibx.msisdn $where AND ibx.folder_id=0 AND ibx.active = 1 ";
		return $this->query($query, true);
    }
    function detail ($id)
    {
        $query = "SELECT * FROM inbox WHERE id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add members and return the new member_id
     *
     */
    function ins($detail)
    {
        return $this->insert('inbox', $detail);
        return $this->last_insert_id('inbox');
    }

    /*
     * Update categories for a particular categories_id
     *
     */
    function edit ($id, $detail)
    {
        return $this->update('inbox', $detail, "id = '$id'");
    }

    /*
     * Delete members detail for a particular member_id
     *
     */
    function deactivate ($id)
    {
        $query = "UPDATE inbox SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id)
    {
        $query = "UPDATE inbox SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
